package com.weipai.springboot.module.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.weipai.springboot.model.CustomerFootprint;
import com.weipai.springboot.model.Goods;
import com.weipai.springboot.model.api.Response;
import com.weipai.springboot.module.service.CustomerFootprintService;
import com.weipai.springboot.module.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by ${lyh} on 2018/8/28.
 *
 * 我的足迹 模块
 */
@RestController
@RequestMapping("/customerfootprint/")
public class CustomerFootprintController {


    @Autowired
    CustomerFootprintService customerFootprintService;
    @Autowired
    GoodsService goodsService;

        /*
                商品足迹 列表
         */
//        @GetMapping("/list/{page}/{size}/{customerId}")
//        public Map<String, Object> list2(@PathVariable("page") Integer page,
//                                        @PathVariable("size") Integer size,
//                                        @PathVariable("customerId") String customerId){
//            Map<String, Object> map = new HashMap<>();
//            PageHelper.startPage(page, size);
////            List<CustomerFootprint> list = customerFootprintService.selectAllByCustomerFootprint(customerId);
//
//                    PageInfo<CustomerFootprint> pageInfo = new PageInfo<>(list);
//                    if(list.size()>0){
//                        map.put("pageData", pageInfo.getList());
//                        map.put("recordsTotal", pageInfo.getTotal());
//                        map.put("pages", pageInfo.getPages());
//                        map.put("code",200);
//                  }else {
//                        map.put("code", 401);
//                        map.put("msg", "暂无数据");
//                    }
//            return map;
//        }

        //商品足迹 列表
        @GetMapping("/list/{page}/{size}/{customerId}")
        public Response list(@PathVariable("page") Integer page,
                      @PathVariable("size") Integer size,
                      @PathVariable("customerId") String customerId) {
            return  customerFootprintService.selectAllByCustomerFootprint(customerId,page,size);
        }



        /*
               单击 添加商品到足迹列表
         */
        @RequestMapping("/goods/save")
        public Response saveGoods(String customerId, String goodsId){
            return customerFootprintService.saveGoods(customerId, goodsId);
        }



        /*
              按客户id 清空 全部足迹
         */
        @RequestMapping("/deleteByCustomer")
        public Response deleteByCustomer(String customerId){
            return customerFootprintService.deleteByCustomer(customerId);
        }



        /*
                批量删除 多个 足迹
         */
        @RequestMapping("/allDel")
        public Response allDel(String[] footprintId){
            return customerFootprintService.allDel(footprintId);
        }



        /*
                单个删除 足迹
         */
        @RequestMapping("/deleteById")
        public Response deleteById(String footprintId){
            return customerFootprintService.deleteById(footprintId);
        }


}
